<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class RubyVM::InstructionSequence - RDoc Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="../Object.html">Object</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-compile">::compile</a>
    <li ><a href="#method-c-compile_file">::compile_file</a>
    <li ><a href="#method-c-compile_option">::compile_option</a>
    <li ><a href="#method-c-compile_option-3D">::compile_option=</a>
    <li ><a href="#method-c-compile_yarp">::compile_yarp</a>
    <li ><a href="#method-c-disasm">::disasm</a>
    <li ><a href="#method-c-disassemble">::disassemble</a>
    <li ><a href="#method-c-load_from_binary">::load_from_binary</a>
    <li ><a href="#method-c-load_from_binary_extra_data">::load_from_binary_extra_data</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-of">::of</a>
    <li ><a href="#method-i-absolute_path">#absolute_path</a>
    <li ><a href="#method-i-base_label">#base_label</a>
    <li ><a href="#method-i-disasm">#disasm</a>
    <li ><a href="#method-i-disassemble">#disassemble</a>
    <li ><a href="#method-i-each_child">#each_child</a>
    <li ><a href="#method-i-eval">#eval</a>
    <li ><a href="#method-i-first_lineno">#first_lineno</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-label">#label</a>
    <li ><a href="#method-i-path">#path</a>
    <li ><a href="#method-i-script_lines">#script_lines</a>
    <li ><a href="#method-i-to_a">#to_a</a>
    <li ><a href="#method-i-to_binary">#to_binary</a>
    <li ><a href="#method-i-trace_points">#trace_points</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-RubyVM::InstructionSequence">
    <h1 id="class-RubyVM::InstructionSequence" class="class">
      class RubyVM::InstructionSequence
    </h1>

    <section class="description">
    
<p>The <a href="InstructionSequence.html"><code>InstructionSequence</code></a> class represents a compiled sequence of instructions for the Virtual Machine used in MRI. Not all implementations of Ruby may implement this class, and for the implementations that implement it, the methods defined and behavior of the methods can change in any version.</p>

<p>With it, you can get a handle to the instructions that make up a method or a proc, compile strings of Ruby code down to VM instructions, and disassemble instruction sequences to strings for easy inspection. It is mostly useful if you want to learn how YARV works, but it also lets you control various settings for the Ruby iseq compiler.</p>

<p>You can find the source for the VM instructions in <code>insns.def</code> in the Ruby source.</p>

<p>The instruction sequence results will almost certainly change as Ruby changes, so example output in this documentation may be different from what you see.</p>

<p>Of course, this class is MRI specific.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-compile" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          compile(source[, file[, path[, line[, options]]]]) &rarr; iseq
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(source[, file[, path[, line[, options]]]]) &rarr; iseq
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Takes <code>source</code>, a <a href="../String.html"><code>String</code></a> of Ruby code and compiles it to an <a href="InstructionSequence.html"><code>InstructionSequence</code></a>.</p>

<p>Optionally takes <code>file</code>, <code>path</code>, and <code>line</code> which describe the file path, real path and first line number of the ruby code in <code>source</code> which are metadata attached to the returned <code>iseq</code>.</p>

<p><code>file</code> is used for ‘__FILE__` and exception backtrace. <code>path</code> is used for <code>require_relative</code> base. It is recommended these should be the same full path.</p>

<p><code>options</code>, which can be <code>true</code>, <code>false</code> or a <code>Hash</code>, is used to modify the default behavior of the Ruby iseq compiler.</p>

<p>For details regarding valid compile options see <a href="InstructionSequence.html#method-c-compile_option-3D"><code>::compile_option=</code></a>.</p>

<pre class="ruby"><span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&quot;a = 1 + 2&quot;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;</span>

<span class="ruby-identifier">path</span> = <span class="ruby-string">&quot;test.rb&quot;</span>
<span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>), <span class="ruby-identifier">path</span>, <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>))
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@test.rb:1&gt;</span>

<span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;test.rb&quot;</span>)
<span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>), <span class="ruby-identifier">path</span>, <span class="ruby-identifier">path</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@/absolute/path/to/test.rb:1&gt;</span>
</pre>

                              <div class="method-source-code" id="compile-source">
            <pre>static VALUE
iseqw_s_compile(int argc, VALUE *argv, VALUE self)
{
    VALUE src, file = Qnil, path = Qnil, line = Qnil, opt = Qnil;
    int i;

    i = rb_scan_args(argc, argv, &quot;1*:&quot;, &amp;src, NULL, &amp;opt);
    if (i &gt; 4+NIL_P(opt)) rb_error_arity(argc, 1, 5);
    switch (i) {
      case 5: opt = argv[--i];
      case 4: line = argv[--i];
      case 3: path = argv[--i];
      case 2: file = argv[--i];
    }

    if (NIL_P(file)) file = rb_fstring_lit(&quot;&lt;compiled&gt;&quot;);
    if (NIL_P(path)) path = file;
    if (NIL_P(line)) line = INT2FIX(1);

    Check_Type(path, T_STRING);
    Check_Type(file, T_STRING);

    return iseqw_new(rb_iseq_compile_with_option(src, file, path, line, opt));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-compile_file" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          compile_file(file[, options]) &rarr; iseq
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Takes <code>file</code>, a <a href="../String.html"><code>String</code></a> with the location of a Ruby source file, reads, parses and compiles the file, and returns <code>iseq</code>, the compiled <a href="InstructionSequence.html"><code>InstructionSequence</code></a> with source location metadata set.</p>

<p>Optionally takes <code>options</code>, which can be <code>true</code>, <code>false</code> or a <code>Hash</code>, to modify the default behavior of the Ruby iseq compiler.</p>

<p>For details regarding valid compile options see <a href="InstructionSequence.html#method-c-compile_option-3D"><code>::compile_option=</code></a>.</p>

<pre class="ruby"><span class="ruby-comment"># /tmp/hello.rb</span>
<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Hello, world!&quot;</span>

<span class="ruby-comment"># elsewhere</span>
<span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile_file</span>(<span class="ruby-string">&quot;/tmp/hello.rb&quot;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;main&gt;@/tmp/hello.rb&gt;</span>
</pre>

                              <div class="method-source-code" id="compile_file-source">
            <pre>static VALUE
iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
{
    VALUE file, opt = Qnil;
    VALUE parser, f, exc = Qnil, ret;
    rb_ast_t *ast;
    rb_compile_option_t option;
    int i;

    i = rb_scan_args(argc, argv, &quot;1*:&quot;, &amp;file, NULL, &amp;opt);
    if (i &gt; 1+NIL_P(opt)) rb_error_arity(argc, 1, 2);
    switch (i) {
      case 2: opt = argv[--i];
    }
    FilePathValue(file);
    file = rb_fstring(file); /* rb_io_t-&gt;pathv gets frozen anyways */

    f = rb_file_open_str(file, &quot;r&quot;);

    rb_execution_context_t *ec = GET_EC();
    VALUE v = rb_vm_push_frame_fname(ec, file);

    parser = rb_parser_new();
    rb_parser_set_context(parser, NULL, FALSE);
    ast = (rb_ast_t *)rb_parser_load_file(parser, file);
    if (!ast-&gt;body.root) exc = GET_EC()-&gt;errinfo;

    rb_io_close(f);
    if (!ast-&gt;body.root) {
        rb_ast_dispose(ast);
        rb_exc_raise(exc);
    }

    make_compile_option(&amp;option, opt);

    ret = iseqw_new(rb_iseq_new_with_opt(&amp;ast-&gt;body, rb_fstring_lit(&quot;&lt;main&gt;&quot;),
                                         file,
                                         rb_realpath_internal(Qnil, file, 1),
                                         1, NULL, 0, ISEQ_TYPE_TOP, &amp;option));
    rb_ast_dispose(ast);

    rb_vm_pop_frame(ec);
    RB_GC_GUARD(v);
    return ret;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-compile_option" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          compile_option &rarr; options
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash of default options used by the Ruby iseq compiler.</p>

<p>For details, see <a href="InstructionSequence.html#method-c-compile_option-3D"><code>InstructionSequence.compile_option=</code></a>.</p>

                              <div class="method-source-code" id="compile_option-source">
            <pre>static VALUE
iseqw_s_compile_option_get(VALUE self)
{
    return make_compile_option_value(&amp;COMPILE_OPTION_DEFAULT);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-compile_option-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          compile_option = options
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the default values for various optimizations in the Ruby iseq compiler.</p>

<p>Possible values for <code>options</code> include <code>true</code>, which enables all options, <code>false</code> which disables all options, and <code>nil</code> which leaves all options unchanged.</p>

<p>You can also pass a <code>Hash</code> of <code>options</code> that you want to change, any options not present in the hash will be left unchanged.</p>

<p>Possible option names (which are keys in <code>options</code>) which can be set to <code>true</code> or <code>false</code> include:</p>
<ul><li>
<p><code>:inline_const_cache</code></p>
</li><li>
<p><code>:instructions_unification</code></p>
</li><li>
<p><code>:operands_unification</code></p>
</li><li>
<p><code>:peephole_optimization</code></p>
</li><li>
<p><code>:specialized_instruction</code></p>
</li><li>
<p><code>:tailcall_optimization</code></p>
</li></ul>

<p>Additionally, <code>:debug_level</code> can be set to an integer.</p>

<p>These default options can be overwritten for a single run of the iseq compiler by passing any of the above values as the <code>options</code> parameter to <a href="InstructionSequence.html#method-c-new"><code>::new</code></a>, <a href="InstructionSequence.html#method-c-compile"><code>::compile</code></a> and <a href="InstructionSequence.html#method-c-compile_file"><code>::compile_file</code></a>.</p>

                              <div class="method-source-code" id="compile_option-3D-source">
            <pre>static VALUE
iseqw_s_compile_option_set(VALUE self, VALUE opt)
{
    rb_compile_option_t option;
    make_compile_option(&amp;option, opt);
    COMPILE_OPTION_DEFAULT = option;
    return opt;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-compile_yarp" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compile_yarp</span><span
                                class="method-args">(p1, *args, p3 = {})</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="compile_yarp-source">
            <pre>static VALUE
iseqw_s_compile_yarp(int argc, VALUE *argv, VALUE self)
{
    VALUE src, file = Qnil, path = Qnil, line = Qnil, opt = Qnil;
    int i;

    i = rb_scan_args(argc, argv, &quot;1*:&quot;, &amp;src, NULL, &amp;opt);
    if (i &gt; 4+NIL_P(opt)) rb_error_arity(argc, 1, 5);
    switch (i) {
      case 5: opt = argv[--i];
      case 4: line = argv[--i];
      case 3: path = argv[--i];
      case 2: file = argv[--i];
    }

    if (NIL_P(file)) file = rb_fstring_lit(&quot;&lt;compiled&gt;&quot;);
    if (NIL_P(path)) path = file;
    if (NIL_P(line)) line = INT2FIX(1);

    Check_Type(path, T_STRING);
    Check_Type(file, T_STRING);

    rb_iseq_t *iseq = iseq_alloc();

    yp_parser_t parser;
    size_t len = RSTRING_LEN(src);
    VALUE name = rb_fstring_lit(&quot;&lt;compiled&gt;&quot;);

    yp_parser_init(&amp;parser, (const uint8_t *) RSTRING_PTR(src), len, &quot;&quot;);

    yp_node_t *node = yp_parse(&amp;parser);

    int first_lineno = NUM2INT(line);
    yp_line_column_t start_loc = yp_newline_list_line_column(&amp;parser.newline_list, node-&gt;location.start);
    yp_line_column_t end_loc = yp_newline_list_line_column(&amp;parser.newline_list, node-&gt;location.end);

    rb_code_location_t node_location;
    node_location.beg_pos.lineno = (int)start_loc.line;
    node_location.beg_pos.column = (int)start_loc.column;
    node_location.end_pos.lineno = (int)end_loc.line;
    node_location.end_pos.column = (int)end_loc.column;

    int node_id = 0;

    rb_iseq_t *parent = NULL;
    enum rb_iseq_type iseq_type = ISEQ_TYPE_TOP;
    rb_compile_option_t option;

    make_compile_option(&amp;option, opt);

    prepare_iseq_build(iseq, name, file, path, first_lineno, &amp;node_location, node_id,
                       parent, 0, (enum rb_iseq_type)iseq_type, Qnil, &amp;option);

    rb_iseq_compile_yarp_node(iseq, node, &amp;parser);

    finish_iseq_build(iseq);
    yp_node_destroy(&amp;parser, node);
    yp_parser_free(&amp;parser);

    return iseqw_new(iseq);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-disasm" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          disasm(body) &rarr; str
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          disassemble(body) &rarr; str
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Takes <code>body</code>, a <a href="../Method.html"><code>Method</code></a> or <a href="../Proc.html"><code>Proc</code></a> object, and returns a <a href="../String.html"><code>String</code></a> with the human readable instructions for <code>body</code>.</p>

<p>For a <a href="../Method.html"><code>Method</code></a> object:</p>

<pre class="ruby"><span class="ruby-comment"># /tmp/method.rb</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;hello, world&quot;</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">puts</span> <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">disasm</span>(<span class="ruby-identifier">method</span>(<span class="ruby-value">:hello</span>))
</pre>

<p>Produces:</p>

<pre>== disasm: &lt;RubyVM::InstructionSequence:hello@/tmp/method.rb&gt;============
0000 trace            8                                               (   1)
0002 trace            1                                               (   2)
0004 putself
0005 putstring        &quot;hello, world&quot;
0007 send             :puts, 1, nil, 8, &lt;ic:0&gt;
0013 trace            16                                              (   3)
0015 leave                                                            (   2)</pre>

<p>For a Proc:</p>

<pre class="ruby"><span class="ruby-comment"># /tmp/proc.rb</span>
<span class="ruby-identifier">p</span> = <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">num</span> = <span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span> }
<span class="ruby-identifier">puts</span> <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">disasm</span>(<span class="ruby-identifier">p</span>)
</pre>

<p>Produces:</p>

<pre>== disasm: &lt;RubyVM::InstructionSequence:block in &lt;main&gt;@/tmp/proc.rb&gt;===
== catch table
| catch type: redo   st: 0000 ed: 0012 sp: 0000 cont: 0000
| catch type: next   st: 0000 ed: 0012 sp: 0000 cont: 0012
|------------------------------------------------------------------------
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] num
0000 trace            1                                               (   1)
0002 putobject        1
0004 putobject        2
0006 opt_plus         &lt;ic:1&gt;
0008 dup
0009 setlocal         num, 0
0012 leave</pre>

                              <div class="method-source-code" id="disasm-source">
            <pre>static VALUE
iseqw_s_disasm(VALUE klass, VALUE body)
{
    VALUE iseqw = iseqw_s_of(klass, body);
    return NIL_P(iseqw) ? Qnil : rb_iseq_disasm(iseqw_check(iseqw));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-disassemble" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          disasm(body) &rarr; str
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          disassemble(body) &rarr; str
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Takes <code>body</code>, a <a href="../Method.html"><code>Method</code></a> or <a href="../Proc.html"><code>Proc</code></a> object, and returns a <a href="../String.html"><code>String</code></a> with the human readable instructions for <code>body</code>.</p>

<p>For a <a href="../Method.html"><code>Method</code></a> object:</p>

<pre class="ruby"><span class="ruby-comment"># /tmp/method.rb</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">hello</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;hello, world&quot;</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">puts</span> <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">disasm</span>(<span class="ruby-identifier">method</span>(<span class="ruby-value">:hello</span>))
</pre>

<p>Produces:</p>

<pre>== disasm: &lt;RubyVM::InstructionSequence:hello@/tmp/method.rb&gt;============
0000 trace            8                                               (   1)
0002 trace            1                                               (   2)
0004 putself
0005 putstring        &quot;hello, world&quot;
0007 send             :puts, 1, nil, 8, &lt;ic:0&gt;
0013 trace            16                                              (   3)
0015 leave                                                            (   2)</pre>

<p>For a Proc:</p>

<pre class="ruby"><span class="ruby-comment"># /tmp/proc.rb</span>
<span class="ruby-identifier">p</span> = <span class="ruby-identifier">proc</span> { <span class="ruby-identifier">num</span> = <span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span> }
<span class="ruby-identifier">puts</span> <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">disasm</span>(<span class="ruby-identifier">p</span>)
</pre>

<p>Produces:</p>

<pre>== disasm: &lt;RubyVM::InstructionSequence:block in &lt;main&gt;@/tmp/proc.rb&gt;===
== catch table
| catch type: redo   st: 0000 ed: 0012 sp: 0000 cont: 0000
| catch type: next   st: 0000 ed: 0012 sp: 0000 cont: 0012
|------------------------------------------------------------------------
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] num
0000 trace            1                                               (   1)
0002 putobject        1
0004 putobject        2
0006 opt_plus         &lt;ic:1&gt;
0008 dup
0009 setlocal         num, 0
0012 leave</pre>

                              <div class="method-source-code" id="disassemble-source">
            <pre>static VALUE
iseqw_s_disasm(VALUE klass, VALUE body)
{
    VALUE iseqw = iseqw_s_of(klass, body);
    return NIL_P(iseqw) ? Qnil : rb_iseq_disasm(iseqw_check(iseqw));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-load_from_binary" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          RubyVM::InstructionSequence.load_from_binary(binary) &rarr; iseq
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Load an iseq object from binary format <a href="../String.html"><code>String</code></a> object created by <a href="InstructionSequence.html#method-i-to_binary"><code>RubyVM::InstructionSequence.to_binary</code></a>.</p>

<p>This loader does not have a verifier, so that loading broken/modified binary causes critical problem.</p>

<p>You should not load binary data provided by others. You should use binary data translated by yourself.</p>

                              <div class="method-source-code" id="load_from_binary-source">
            <pre>static VALUE
iseqw_s_load_from_binary(VALUE self, VALUE str)
{
    return iseqw_new(rb_iseq_ibf_load(str));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-load_from_binary_extra_data" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          RubyVM::InstructionSequence.load_from_binary_extra_data(binary) &rarr; str
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Load extra data embed into binary format <a href="../String.html"><code>String</code></a> object.</p>

                              <div class="method-source-code" id="load_from_binary_extra_data-source">
            <pre>static VALUE
iseqw_s_load_from_binary_extra_data(VALUE self, VALUE str)
{
    return rb_iseq_ibf_load_extra_data(str);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          compile(source[, file[, path[, line[, options]]]]) &rarr; iseq
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(source[, file[, path[, line[, options]]]]) &rarr; iseq
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Takes <code>source</code>, a <a href="../String.html"><code>String</code></a> of Ruby code and compiles it to an <a href="InstructionSequence.html"><code>InstructionSequence</code></a>.</p>

<p>Optionally takes <code>file</code>, <code>path</code>, and <code>line</code> which describe the file path, real path and first line number of the ruby code in <code>source</code> which are metadata attached to the returned <code>iseq</code>.</p>

<p><code>file</code> is used for ‘__FILE__` and exception backtrace. <code>path</code> is used for <code>require_relative</code> base. It is recommended these should be the same full path.</p>

<p><code>options</code>, which can be <code>true</code>, <code>false</code> or a <code>Hash</code>, is used to modify the default behavior of the Ruby iseq compiler.</p>

<p>For details regarding valid compile options see <a href="InstructionSequence.html#method-c-compile_option-3D"><code>::compile_option=</code></a>.</p>

<pre class="ruby"><span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&quot;a = 1 + 2&quot;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;</span>

<span class="ruby-identifier">path</span> = <span class="ruby-string">&quot;test.rb&quot;</span>
<span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>), <span class="ruby-identifier">path</span>, <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">path</span>))
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@test.rb:1&gt;</span>

<span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;test.rb&quot;</span>)
<span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>), <span class="ruby-identifier">path</span>, <span class="ruby-identifier">path</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@/absolute/path/to/test.rb:1&gt;</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
iseqw_s_compile(int argc, VALUE *argv, VALUE self)
{
    VALUE src, file = Qnil, path = Qnil, line = Qnil, opt = Qnil;
    int i;

    i = rb_scan_args(argc, argv, &quot;1*:&quot;, &amp;src, NULL, &amp;opt);
    if (i &gt; 4+NIL_P(opt)) rb_error_arity(argc, 1, 5);
    switch (i) {
      case 5: opt = argv[--i];
      case 4: line = argv[--i];
      case 3: path = argv[--i];
      case 2: file = argv[--i];
    }

    if (NIL_P(file)) file = rb_fstring_lit(&quot;&lt;compiled&gt;&quot;);
    if (NIL_P(path)) path = file;
    if (NIL_P(line)) line = INT2FIX(1);

    Check_Type(path, T_STRING);
    Check_Type(file, T_STRING);

    return iseqw_new(rb_iseq_compile_with_option(src, file, path, line, opt));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-of" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">of</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the instruction sequence containing the given proc or method.</p>

<p>For example, using irb:</p>

<pre># a proc
&gt; p = proc { num = 1 + 2 }
&gt; RubyVM::InstructionSequence.of(p)
&gt; #=&gt; &lt;RubyVM::InstructionSequence:block in irb_binding@(irb)&gt;

# for a method
&gt; def foo(bar); puts bar; end
&gt; RubyVM::InstructionSequence.of(method(:foo))
&gt; #=&gt; &lt;RubyVM::InstructionSequence:foo@(irb)&gt;</pre>

<p>Using <a href="InstructionSequence.html#method-c-compile_file"><code>::compile_file</code></a>:</p>

<pre># /tmp/iseq_of.rb
def hello
  puts &quot;hello, world&quot;
end

$a_global_proc = proc { str = &#39;a&#39; + &#39;b&#39; }

# in irb
&gt; require &#39;/tmp/iseq_of.rb&#39;

# first the method hello
&gt; RubyVM::InstructionSequence.of(method(:hello))
&gt; #=&gt; #&lt;RubyVM::InstructionSequence:0x007fb73d7cb1d0&gt;

# then the global proc
&gt; RubyVM::InstructionSequence.of($a_global_proc)
&gt; #=&gt; #&lt;RubyVM::InstructionSequence:0x007fb73d7caf78&gt;</pre>

                              <div class="method-source-code" id="of-source">
            <pre>static VALUE
iseqw_s_of(VALUE klass, VALUE body)
{
    const rb_iseq_t *iseq = NULL;

    if (rb_obj_is_proc(body)) {
        iseq = vm_proc_iseq(body);

        if (!rb_obj_is_iseq((VALUE)iseq)) {
            iseq = NULL;
        }
    }
    else if (rb_obj_is_method(body)) {
        iseq = rb_method_iseq(body);
    }
    else if (rb_typeddata_is_instance_of(body, &amp;iseqw_data_type)) {
        return body;
    }

    return iseq ? iseqw_new(iseq) : Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-absolute_path" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">absolute_path</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the absolute path of this instruction sequence.</p>

<p><code>nil</code> if the iseq was evaluated from a string.</p>

<p>For example, using <a href="InstructionSequence.html#method-c-compile_file"><code>::compile_file</code></a>:</p>

<pre># /tmp/method.rb
def hello
  puts &quot;hello, world&quot;
end

# in irb
&gt; iseq = RubyVM::InstructionSequence.compile_file(&#39;/tmp/method.rb&#39;)
&gt; iseq.absolute_path #=&gt; /tmp/method.rb</pre>

                              <div class="method-source-code" id="absolute_path-source">
            <pre>static VALUE
iseqw_absolute_path(VALUE self)
{
    return rb_iseq_realpath(iseqw_check(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-base_label" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">base_label</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the base label of this instruction sequence.</p>

<p>For example, using irb:</p>

<pre class="ruby"><span class="ruby-identifier">iseq</span> = <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&#39;num = 1 + 2&#39;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;</span>
<span class="ruby-identifier">iseq</span>.<span class="ruby-identifier">base_label</span>
<span class="ruby-comment">#=&gt; &quot;&lt;compiled&gt;&quot;</span>
</pre>

<p>Using <a href="InstructionSequence.html#method-c-compile_file"><code>::compile_file</code></a>:</p>

<pre># /tmp/method.rb
def hello
  puts &quot;hello, world&quot;
end

# in irb
&gt; iseq = RubyVM::InstructionSequence.compile_file(&#39;/tmp/method.rb&#39;)
&gt; iseq.base_label #=&gt; &lt;main&gt;</pre>

                              <div class="method-source-code" id="base_label-source">
            <pre>static VALUE
iseqw_base_label(VALUE self)
{
    return rb_iseq_base_label(iseqw_check(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-disasm" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          disasm &rarr; str
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the instruction sequence as a <code>String</code> in human readable form.</p>

<pre class="ruby"><span class="ruby-identifier">puts</span> <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&#39;1 + 2&#39;</span>).<span class="ruby-identifier">disasm</span>
</pre>

<p>Produces:</p>

<pre>== disasm: &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;==========
0000 trace            1                                               (   1)
0002 putobject        1
0004 putobject        2
0006 opt_plus         &lt;ic:1&gt;
0008 leave</pre>

                              <div class="method-source-code" id="disasm-source">
            <pre>static VALUE
iseqw_disasm(VALUE self)
{
    return rb_iseq_disasm(iseqw_check(self));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="InstructionSequence.html#method-i-disassemble">disassemble</a>, disassemble
                            </div>

                          </div>

                  <div id="method-i-disassemble" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          disassemble &rarr; str
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the instruction sequence as a <code>String</code> in human readable form.</p>

<pre class="ruby"><span class="ruby-identifier">puts</span> <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&#39;1 + 2&#39;</span>).<span class="ruby-identifier">disasm</span>
</pre>

<p>Produces:</p>

<pre>== disasm: &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;==========
0000 trace            1                                               (   1)
0002 putobject        1
0004 putobject        2
0006 opt_plus         &lt;ic:1&gt;
0008 leave</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="InstructionSequence.html#method-i-disasm">disasm</a>
                            </div>
                          </div>

                  <div id="method-i-each_child" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_child{|child_iseq| ...} &rarr; iseq
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterate all direct child instruction sequences. Iteration order is implementation/version defined so that people should not rely on the order.</p>

                              <div class="method-source-code" id="each_child-source">
            <pre>static VALUE
iseqw_each_child(VALUE self)
{
    const rb_iseq_t *iseq = iseqw_check(self);
    iseq_iterate_children(iseq, yield_each_children, NULL);
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eval" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eval &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Evaluates the instruction sequence and returns the result.</p>

<pre class="ruby"><span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&quot;1 + 2&quot;</span>).<span class="ruby-identifier">eval</span> <span class="ruby-comment">#=&gt; 3</span>
</pre>

                              <div class="method-source-code" id="eval-source">
            <pre>static VALUE
iseqw_eval(VALUE self)
{
    return rb_iseq_eval(iseqw_check(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-first_lineno" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">first_lineno</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the number of the first source line where the instruction sequence was loaded from.</p>

<p>For example, using irb:</p>

<pre class="ruby"><span class="ruby-identifier">iseq</span> = <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&#39;num = 1 + 2&#39;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;</span>
<span class="ruby-identifier">iseq</span>.<span class="ruby-identifier">first_lineno</span>
<span class="ruby-comment">#=&gt; 1</span>
</pre>

                              <div class="method-source-code" id="first_lineno-source">
            <pre>static VALUE
iseqw_first_lineno(VALUE self)
{
    return rb_iseq_first_lineno(iseqw_check(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a human-readable string representation of this instruction sequence, including the <a href="InstructionSequence.html#method-i-label"><code>label</code></a> and <a href="InstructionSequence.html#method-i-path"><code>path</code></a>.</p>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
iseqw_inspect(VALUE self)
{
    const rb_iseq_t *iseq = iseqw_check(self);
    const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
    VALUE klass = rb_class_name(rb_obj_class(self));

    if (!body-&gt;location.label) {
        return rb_sprintf(&quot;#&lt;%&quot;PRIsVALUE&quot;: uninitialized&gt;&quot;, klass);
    }
    else {
        return rb_sprintf(&quot;&lt;%&quot;PRIsVALUE&quot;:%&quot;PRIsVALUE&quot;@%&quot;PRIsVALUE&quot;:%d&gt;&quot;,
                          klass,
                          body-&gt;location.label, rb_iseq_path(iseq),
                          FIX2INT(rb_iseq_first_lineno(iseq)));
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-label" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">label</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the label of this instruction sequence.</p>

<p><code>&lt;main&gt;</code> if it’s at the top level, <code>&lt;compiled&gt;</code> if it was evaluated from a string.</p>

<p>For example, using irb:</p>

<pre class="ruby"><span class="ruby-identifier">iseq</span> = <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&#39;num = 1 + 2&#39;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;</span>
<span class="ruby-identifier">iseq</span>.<span class="ruby-identifier">label</span>
<span class="ruby-comment">#=&gt; &quot;&lt;compiled&gt;&quot;</span>
</pre>

<p>Using <a href="InstructionSequence.html#method-c-compile_file"><code>::compile_file</code></a>:</p>

<pre># /tmp/method.rb
def hello
  puts &quot;hello, world&quot;
end

# in irb
&gt; iseq = RubyVM::InstructionSequence.compile_file(&#39;/tmp/method.rb&#39;)
&gt; iseq.label #=&gt; &lt;main&gt;</pre>

                              <div class="method-source-code" id="label-source">
            <pre>static VALUE
iseqw_label(VALUE self)
{
    return rb_iseq_label(iseqw_check(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-path" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">path</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the path of this instruction sequence.</p>

<p><code>&lt;compiled&gt;</code> if the iseq was evaluated from a string.</p>

<p>For example, using irb:</p>

<pre class="ruby"><span class="ruby-identifier">iseq</span> = <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span>.<span class="ruby-identifier">compile</span>(<span class="ruby-string">&#39;num = 1 + 2&#39;</span>)
<span class="ruby-comment">#=&gt; &lt;RubyVM::InstructionSequence:&lt;compiled&gt;@&lt;compiled&gt;&gt;</span>
<span class="ruby-identifier">iseq</span>.<span class="ruby-identifier">path</span>
<span class="ruby-comment">#=&gt; &quot;&lt;compiled&gt;&quot;</span>
</pre>

<p>Using <a href="InstructionSequence.html#method-c-compile_file"><code>::compile_file</code></a>:</p>

<pre># /tmp/method.rb
def hello
  puts &quot;hello, world&quot;
end

# in irb
&gt; iseq = RubyVM::InstructionSequence.compile_file(&#39;/tmp/method.rb&#39;)
&gt; iseq.path #=&gt; /tmp/method.rb</pre>

                              <div class="method-source-code" id="path-source">
            <pre>static VALUE
iseqw_path(VALUE self)
{
    return rb_iseq_path(iseqw_check(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-script_lines" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          script_lines &rarr; array or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>It returns recorded script lines if it is available. The script lines are not limited to the iseq range, but are entire lines of the source file.</p>

<p>Note that this is an API for ruby internal use, debugging, and research. Do not use this for any other purpose. The compatibility is not guaranteed.</p>

                              <div class="method-source-code" id="script_lines-source">
            <pre>static VALUE
iseqw_script_lines(VALUE self)
{
    const rb_iseq_t *iseq = iseqw_check(self);
    return ISEQ_BODY(iseq)-&gt;variable.script_lines;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_a" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_a &rarr; ary
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an <a href="../Array.html"><code>Array</code></a> with 14 elements representing the instruction sequence with the following data:</p>
<dl class="rdoc-list label-list"><dt>magic
<dd>
<p>A string identifying the data format. <strong>Always <code>YARVInstructionSequence/SimpleDataFormat</code>.</strong></p>
</dd><dt>major_version
<dd>
<p>The major version of the instruction sequence.</p>
</dd><dt>minor_version
<dd>
<p>The minor version of the instruction sequence.</p>
</dd><dt>format_type
<dd>
<p>A number identifying the data format. <strong>Always 1</strong>.</p>
</dd><dt>misc
<dd>
<p>A hash containing:</p>
<dl class="rdoc-list label-list"><dt><code>:arg_size</code>
<dd>
<p>the total number of arguments taken by the method or the block (0 if <em>iseq</em> doesn’t represent a method or block)</p>
</dd><dt><code>:local_size</code>
<dd>
<p>the number of local variables + 1</p>
</dd><dt><code>:stack_max</code>
<dd>
<p>used in calculating the stack depth at which a <a href="../SystemStackError.html"><code>SystemStackError</code></a> is thrown.</p>
</dd></dl>
</dd><dt><a href="InstructionSequence.html#method-i-label"><code>label</code></a>
<dd>
<p>The name of the context (block, method, class, module, etc.) that this instruction sequence belongs to.</p>

<p><code>&lt;main&gt;</code> if it’s at the top level, <code>&lt;compiled&gt;</code> if it was evaluated from a string.</p>
</dd><dt><a href="InstructionSequence.html#method-i-path"><code>path</code></a>
<dd>
<p>The relative path to the Ruby file where the instruction sequence was loaded from.</p>

<p><code>&lt;compiled&gt;</code> if the iseq was evaluated from a string.</p>
</dd><dt><a href="InstructionSequence.html#method-i-absolute_path"><code>absolute_path</code></a>
<dd>
<p>The absolute path to the Ruby file where the instruction sequence was loaded from.</p>

<p><code>nil</code> if the iseq was evaluated from a string.</p>
</dd><dt><a href="InstructionSequence.html#method-i-first_lineno"><code>first_lineno</code></a>
<dd>
<p>The number of the first source line where the instruction sequence was loaded from.</p>
</dd><dt>type
<dd>
<p>The type of the instruction sequence.</p>

<p>Valid values are <code>:top</code>, <code>:method</code>, <code>:block</code>, <code>:class</code>, <code>:rescue</code>, <code>:ensure</code>, <code>:eval</code>, <code>:main</code>, and <code>plain</code>.</p>
</dd><dt>locals
<dd>
<p>An array containing the names of all arguments and local variables as symbols.</p>
</dd><dt>params
<dd>
<p>An <a href="../Hash.html"><code>Hash</code></a> object containing parameter information.</p>

<p>More info about these values can be found in <code>vm_core.h</code>.</p>
</dd><dt>catch_table
<dd>
<p>A list of exceptions and control flow operators (rescue, next, redo, break, etc.).</p>
</dd><dt>bytecode
<dd>
<p>An array of arrays containing the instruction names and operands that make up the body of the instruction sequence.</p>
</dd></dl>

<p>Note that this format is MRI specific and version dependent.</p>

                              <div class="method-source-code" id="to_a-source">
            <pre>static VALUE
iseqw_to_a(VALUE self)
{
    const rb_iseq_t *iseq = iseqw_check(self);
    return iseq_data_to_ary(iseq);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_binary" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_binary(extra_data = nil) &rarr; binary str
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns serialized iseq binary format data as a <a href="../String.html"><code>String</code></a> object. A corresponding iseq object is created by <a href="InstructionSequence.html#method-c-load_from_binary"><code>RubyVM::InstructionSequence.load_from_binary()</code></a> method.</p>

<p><a href="../String.html"><code>String</code></a> extra_data will be saved with binary data. You can access this data with <a href="InstructionSequence.html#method-c-load_from_binary_extra_data"><code>RubyVM::InstructionSequence.load_from_binary_extra_data(binary)</code></a>.</p>

<p>Note that the translated binary data is not portable. You can not move this binary data to another machine. You can not use the binary data which is created by another version/another architecture of Ruby.</p>

                              <div class="method-source-code" id="to_binary-source">
            <pre>static VALUE
iseqw_to_binary(int argc, VALUE *argv, VALUE self)
{
    VALUE opt = !rb_check_arity(argc, 0, 1) ? Qnil : argv[0];
    return rb_iseq_ibf_dump(iseqw_check(self), opt);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-trace_points" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          trace_points &rarr; ary
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Return trace points in the instruction sequence. Return an array of [line, event_symbol] pair.</p>

                              <div class="method-source-code" id="trace_points-source">
            <pre>static VALUE
iseqw_trace_points(VALUE self)
{
    const rb_iseq_t *iseq = iseqw_check(self);
    const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
    unsigned int i;
    VALUE ary = rb_ary_new();

    for (i=0; i&lt;body-&gt;insns_info.size; i++) {
        const struct iseq_insn_info_entry *entry = &amp;body-&gt;insns_info.body[i];
        if (entry-&gt;events) {
            push_event_info(iseq, entry-&gt;events, entry-&gt;line_no, ary);
        }
    }
    return ary;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

